using System;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

using Derived = OR.Lazarus.Business.Entities.Log;

namespace OR.Lazarus.Business.Entities.Log.Lazarus
{
	/// <summary>
	/// Defines a Log of Lazarus Compiler events.
	/// </summary>
   public class LogDetail : EntityBase
   {
		protected System.String mName;
	
		protected Derived.CompiledLogCollection mCompiles;

		public LogDetail()
		{
			mCompiles = new Derived.CompiledLogCollection();
			mCompiles.ParentEntity = this;
	
		}
	
		/// <summary>
		/// 
		/// </summary>
		public System.String Name
		{
			get
			{
				return ( mName );
			}
			set
			{
				mName = value;
			}
		}

		public Derived.CompiledLogCollection Compiles
		{
			get
			{
				return ( mCompiles );
			}
			set
			{
				mCompiles = value;
			}
		}

		public override void LoadXml( XmlElement pSource )
		{
			// Scalar Values
			mName = DataUtility.GetString( pSource, "name" );
			XmlElement vCompiles = ( XmlElement )pSource.SelectSingleNode( "lzl:compiles", PersistenceConfig.Namespaces );
			
			if ( vCompiles != null )
			{
				mCompiles.LoadXml( vCompiles );
			}
		}
		
		public override XmlElement SaveXml( XmlDocument p_docContext )
		{
			XmlElement vNewElement	= p_docContext.CreateElement( "lzl", "Log", "http://schemas.icitadel.com/Lazarus/Log.xsd" );

			// Scalar Values
			if ( !String.IsNullOrEmpty( mName ) )
			{
				vNewElement.SetAttribute( "name", mName );
			}
					

			// Collections
			
			XmlElement	vCollection	= null;
			
			vCollection = mCompiles.SaveXml( p_docContext );
			if ( vCollection != null )
			{
				vNewElement.AppendChild( vCollection );
			}

			return ( vNewElement );
		}

		public virtual object Clone()
		{
			Derived.LogDetail v_oReturn = new Derived.LogDetail();
			
			v_oReturn.Name = mName;
			
			// FK Values

			// Collections

			foreach ( Derived.CompiledLogDetail vDetail in mCompiles )
			{
				v_oReturn.Compiles.Add( vDetail.CloneTyped() );
			}
			
			return ( v_oReturn );
		}

		public virtual Derived.LogDetail CloneTyped()
		{
			return ( ( Derived.LogDetail )this.Clone() );
		}
   }
}
   